# @Version        : 1.0
# @Update Time    : 2025/3/15 23:59
# @File           : product_service.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息

class ProductService:
    def get_hot_products(self):
        # 模拟从数据库或其他数据源获取热门商品数据
        return [
            {"id": 1, "image": "assets/fruit/22852ad7-8e84-4e9a-a173-79e4265c73a0.png",
             "title": "新鲜草莓", "rating": 4.5, "weight": "1.5kg",
             "price": "¥10.00", "reviews": [
                {"user": "吃货小美", "rating": 5, "comment": "草莓非常新鲜，收到货时还有冰袋保鲜，会回购！"},
                {"user": "水果达人", "rating": 4, "comment": "味道不错，就是有点小贵。"}
            ], "specifications": self._generate_specifications()},
            {"id": 2, "image": "assets/fruit/apple.png",
             "title": "有机苹果", "rating": 4.0, "weight": "1.6kg",
             "price": "¥5.00", "reviews": [
                {"user": "吃货小美", "rating": 5, "comment": "有机苹果非常新鲜，收到货时还有冰袋保鲜，会回购！"},
                {"user": "水果达人", "rating": 4, "comment": "味道不错，就是有点小贵。"},
                {"user": "健康生活", "rating": 5, "comment": "有机水果，吃得放心。"},
            ], "specifications": self._generate_specifications()},
            {"id": 3, "image": "assets/fruit/92b9a2de-b05f-4e69-b87c-d665a0150543.png",
             "title": "牛油果", "rating": 4.9, "weight": "1.2kg",
             "price": "¥8.00", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
            {"id": 4, "image": "assets/fruit/bocai.png",
             "title": "有机菠菜", "rating": 5.0, "weight": "1.4kg",
             "price": "¥20.00", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
            {"id": 5, "image": "assets/fruit/6206ddcc-df2a-4258-96dd-e9400ed25da8.png",
             "title": "车厘子", "rating": 5.0, "weight": "1.4kg",
             "price": "¥40.00", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
            {"id": 6, "image": "assets/fruit/aa4d8663-f42c-4fe0-9c5f-66b4f80fdcbc.png",
             "title": "天山雪梨", "rating": 5.0, "weight": "1.4kg",
             "price": "¥60.00", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
            {"id": 7, "image": "assets/fruit/949523d7-ba77-481a-bc97-8df3ca3ad6e1.png",
             "title": "猕猴桃", "rating": 5.0, "weight": "1.4kg",
             "price": "¥10.99", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
            {"id": 8, "image": "assets/fruit/5fece989-fc8f-46b2-95f8-28c3675e506e.png",
             "title": "石榴", "rating": 5.0, "weight": "1.4kg",
             "price": "¥50.00", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
            {"id": 9, "image": "assets/fruit/27e06877-2cf4-499e-87d0-b9477ce6763e.png",
             "title": "新疆葡萄", "rating": 5.0, "weight": "1.4kg",
             "price": "¥80.00", "reviews": self._generate_reviews(), "specifications": self._generate_specifications()},
        ]

    def _generate_reviews(self):
        # 生成动态的假评论数据
        return [
            {"user": "吃货小美", "rating": 5, "comment": "芒果非常新鲜，收到货时还有冰袋保鲜，会回购！"},
            {"user": "水果达人", "rating": 4, "comment": "味道不错，就是有点小贵。"},
            {"user": "健康生活", "rating": 5, "comment": "有机水果，吃得放心。"},
            {"user": "美食家", "rating": 3, "comment": "包装很好，但口感一般。"},
            {"user": "水果爱好者", "rating": 5, "comment": "非常满意，下次还会购买。"}
        ]

    def _generate_specifications(self):
        # 生成动态的假规格数据
        return [
            {"size": "3个装", "price": "¥10.00"},
            {"size": "5个装", "price": "¥15.00"},
            {"size": "8个装", "price": "¥20.00"}
        ]

    # 根据id查询数据
    def get_product_by_id(self, data_id) -> dict:
        # 模拟从数据库或其他数据源获取商品数据
        for product in self.get_hot_products():
            if product["id"] == data_id:
                return product
